<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"www.lixiaofei.cn","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":true,"storage":true,"lazyload":true,"nav":{"valine":{"order":-1}}},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="前面写的将博客迁移到阿里云的文章中，没有详细说明如何设置 SSH 公钥免密登录，今天就这个话题详细说明以下，希望对有自己服务器或者对服务器管理感兴趣的朋友有所帮助">
<meta property="og:type" content="article">
<meta property="og:title" content="如何设置 SSH 免密登录">
<meta property="og:url" content="http://www.lixiaofei.cn/2020-08-06-login-by-ssh/index.html">
<meta property="og:site_name" content="管窥程序">
<meta property="og:description" content="前面写的将博客迁移到阿里云的文章中，没有详细说明如何设置 SSH 公钥免密登录，今天就这个话题详细说明以下，希望对有自己服务器或者对服务器管理感兴趣的朋友有所帮助">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://www.lixiaofei.cn/images/2020/08/ssh-nopasswd-login/00.jpg">
<meta property="og:image" content="http://www.lixiaofei.cn/images/2020/08/ssh-nopasswd-login/01.jpg">
<meta property="og:image" content="http://www.lixiaofei.cn/images/2020/08/ssh-nopasswd-login/02.jpg">
<meta property="og:image" content="http://www.lixiaofei.cn/images/2020/08/ssh-nopasswd-login/03.jpg">
<meta property="og:image" content="http://www.lixiaofei.cn/images/2020/08/ssh-nopasswd-login/04.jpg">
<meta property="og:image" content="http://www.lixiaofei.cn/images/2020/08/ssh-nopasswd-login/05.jpg">
<meta property="article:published_time" content="2020-08-06T09:52:55.000Z">
<meta property="article:modified_time" content="2020-08-06T05:01:30.912Z">
<meta property="article:author" content="太阳雪">
<meta property="article:tag" content="Linux">
<meta property="article:tag" content="ssh">
<meta property="article:tag" content="key">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://www.lixiaofei.cn/images/2020/08/ssh-nopasswd-login/00.jpg">

<link rel="canonical" href="http://www.lixiaofei.cn/2020-08-06-login-by-ssh/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>如何设置 SSH 免密登录 | 管窥程序</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">管窥程序</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Today is a gift</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

  <a href="https://github.com/alisx" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://www.lixiaofei.cn/2020-08-06-login-by-ssh/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="太阳雪">
      <meta itemprop="description" content="总结 技术 思考 想法">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="管窥程序">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          如何设置 SSH 免密登录
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-08-06 17:52:55 / 修改时间：13:01:30" itemprop="dateCreated datePublished" datetime="2020-08-06T17:52:55+08:00">2020-08-06</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%AD%A6%E4%B8%8E%E8%B7%B5/" itemprop="url" rel="index"><span itemprop="name">学与践</span></a>
                </span>
            </span>

          
            <span id="/2020-08-06-login-by-ssh/" class="post-meta-item leancloud_visitors" data-flag-title="如何设置 SSH 免密登录" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020-08-06-login-by-ssh/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020-08-06-login-by-ssh/" itemprop="commentCount"></span>
    </a>
  </span>
  
  

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p><img src="/images/2020/08/ssh-nopasswd-login/00.jpg" alt="ssh"><br>
前面写的将博客迁移到阿里云的文章中，没有详细说明如何设置 SSH 公钥免密登录，今天就这个话题详细说明以下，希望对有自己服务器或者对服务器管理感兴趣的朋友有所帮助</p>
<a id="more"></a>
<h2 id="什么是-SSH">什么是 SSH</h2>
<p>SSH 是一种网络协议，用于计算机之间的加密登录，如果使用 SSH 协议登录远程计算机，就可以认为是安全登录，即使通信数据保被截获，密码或者内容也不会泄漏。</p>
<p>SSH 是 1995 年，芬兰学者 Tatu Ylongen 设计的，推出之后迅速在全世界推广开，已然成为互联网安全的一个基本解决方案，而且成为了 Linux 系统的标配</p>
<p>SSH 只是一种协议，存在不同版本的实现，在 Linux 中，标配的是 OpenSSH 开源实现，还记得有场罗永浩的手机发布会，将全部的门票收入捐赠给了 OpenSSH，Windows 上，用的实现了 SSH 协议的 Putty 软件</p>
<h2 id="为什么要免密">为什么要免密</h2>
<p>ssh 支持密码登录和公钥登录，无论是用哪种方式，通信都是经过加密的，是安全的</p>
<p>不过用密码登录不方便，每次都需要输入用户名，密码，很不方便，同时增加密码泄漏的风险</p>
<p>另外在一些软件，如 Git，提供了 SSH 支持，会使开发效率更高，同时不必存储明文密码</p>
<p>作为运维人员，需要同时管理多台机器，记住每台的密码是困难和不可考的，通过 SSH 公钥将大大减轻工作负荷</p>
<p>……</p>
<h2 id="设置-SSH">设置 SSH</h2>
<p>了解了 SSH 的基本情况，下面了解下设置步骤</p>
<h3 id="1-制作密钥对">1 制作密钥对</h3>
<p>SSH 的密钥需要有足够的安全性，另外需要有一定的格式，每个实现 SSH 协议的软件，都提供了密钥生成工具，Linux 中的是 ssh-keygen， Windows 中 Putty 会带一个 puttygen</p>
<p>下面分别做下声明</p>
<h4 id="ssh-keygen">ssh-keygen</h4>
<p>打开终端，输入 <code>ssh-keygen</code></p>
<p>然后会提示输入密钥文件存储位置及名称，默认会在当前登录用户家目录下，密钥文件名为 id_rsa</p>
<p>之后提示输入密钥的密码，这是为了防止密钥被泄漏，被别人利用的风险，只是自己来用的话可以不用设置密码，直接回车就行</p>
<p>确认密码时继续回车</p>
<p>此时密钥就生成好了，有类似下提示（你的一定与下面的不同，因为生成过程是随机的）：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">Your identification has been saved <span class="keyword">in</span> /home/alisx/id_rsa</span><br><span class="line">Your public key has been saved <span class="keyword">in</span> /home/alisx/id_rsa.pub</span><br><span class="line">The key fingerprint is:</span><br><span class="line">SHA256:K7H4cfgm0oIutSJ4Pq61e9253JBf40tLQnYiY6WDfv8 alisx@alisx-HP-EliteBook-840-G2</span><br><span class="line">The key<span class="string">'s randomart image is:</span></span><br><span class="line"><span class="string">+---[RSA 3072]----+</span></span><br><span class="line"><span class="string">|                 |</span></span><br><span class="line"><span class="string">|                 |</span></span><br><span class="line"><span class="string">|          .      |</span></span><br><span class="line"><span class="string">|       . o       |</span></span><br><span class="line"><span class="string">|      o S + .    |</span></span><br><span class="line"><span class="string">|  .  o = O o     |</span></span><br><span class="line"><span class="string">|...o.o*.*.. =    |</span></span><br><span class="line"><span class="string">|=.=.+.+B+= * o   |</span></span><br><span class="line"><span class="string">|oO*+ o.o+.+.E.   |</span></span><br><span class="line"><span class="string">+----[SHA256]-----+</span></span><br></pre></td></tr></table></figure>
<p>然后在刚才输入的密钥目录，就会有 <code>id_rsa</code> 和 <code>id_rsa.pub</code> 两个文件，分别是私钥文件和公钥文件（文件名，取决于输入的密码文件名）</p>
<h4 id="puttygen">puttygen</h4>
<p>putty 实现了 SSH，不过密钥文件格式与 OpenSSH 有所不同，所以在将公钥推送到 Linux 服务器上时，需要转化成 OpenSSH 的密钥文件格式</p>
<p>打开 puttygen</p>
<blockquote>
<p>一般会随 putty 一起安装，与 putty 在同一目录下，putty 在这里下载： <a href="https://puttygen.com/download.php?val=4" target="_blank" rel="noopener">https://puttygen.com/download.php?val=4</a></p>
</blockquote>
<p>点击 <code>Genrate</code> 按钮</p>
<p><img src="/images/2020/08/ssh-nopasswd-login/01.jpg" alt="生成"></p>
<p>然后在空白区域随即晃动鼠标，以便生成随机量，产生更安全的密钥对</p>
<p><img src="/images/2020/08/ssh-nopasswd-login/02.jpg" alt="生成过程"></p>
<p>生成完后，就能看到密钥信息了</p>
<p><img src="/images/2020/08/ssh-nopasswd-login/03.jpg" alt="密钥信息"></p>
<p>通过 <code>Save public key</code> 和 <code>Save private key</code> 按钮保存的密钥文件格式是 Putty 的，OpenSSH 格式的公钥在上面的只读文本框里，选择复制，粘贴到文本文件中，例如命名为: <code>id_rsa.pub</code>，就得到了 OpenSSH 格式的公钥文件了</p>
<p><img src="/images/2020/08/ssh-nopasswd-login/04.jpg" alt="OpenSSH 公钥"></p>
<h3 id="2-向服务器推送公钥">2 向服务器推送公钥</h3>
<p>需要将公钥内容让远程服务器知道，才能用对应的私钥登录</p>
<h4 id="ssh-copy-id">ssh-copy-id</h4>
<p>Linux 中，可以用 ssh-copy-id 来推送，在终端中输入：</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh-copy-id -i &lt;公钥文件路径&gt;  &lt;user&gt;@&lt;服务器名或者 IP &gt;</span><br></pre></td></tr></table></figure>
<p>如果服务可以联通，且是第一次连接的话，会得到提示是否确认远程服务器的指纹，确定没有连接错主机的话，输入 yes</p>
<blockquote>
<p>实际上 <code>确定没有连接错主机</code> 不够严谨，如果主机是通过主机名连接的，可能会有 DNS 攻击风险，看起来连上了，实际上连接的是别的机器，请注意</p>
</blockquote>
<p>然后输入登录密码（因为还没有密钥，需要用密码登录），完成推送</p>
<p>此时就可以用密钥登录服务器了</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh u&lt;user&gt;@&lt;服务器名或者 IP &gt;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>需要注意的是，在 Linux 下用 ssh 登录远程服务器，会在当前家目录 .ssh 下找私钥，如果私钥没在 .ssh 下，需要用参数 <code>-i</code> 指定私钥路径</p>
<p>另外请注意，ssh-copy-id 中 <code>-i</code> 指定的是要推送到服务器的公钥，ssh 中 <code>-i</code> 指定的是私钥</p>
</blockquote>
<h4 id="手工推送">手工推送</h4>
<p>Windows 下没有 ssh-copy-id 工具，需要手工向服务器推送</p>
<p>使用用户名，密码连接到远程主机，打开用户家目录下 <code>.ssh/authorized_keys</code> 文件，将刚才用 puttygen 生成的 id_rsa.pub 文件内容（注意只有一行），粘贴到 <code>authorized_keys</code> 中即可</p>
<p>对于新主机，或者服务器上的新用户来说，没有 <code>.ssh</code> 文件夹，就需要创建一个</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir ~/.ssh</span><br></pre></td></tr></table></figure>
<p>在创建 <code>authorized_keys</code> 文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">touch ~/.ssh/authorized_keys</span><br></pre></td></tr></table></figure>
<p>然后，修改 <code>.ssh</code> 目录 和 <code>authorized_keys</code> 文件的权限</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">chmod 700 ~/.ssh</span><br><span class="line"></span><br><span class="line">chmod 600 ~/.ssh/authorized_keys</span><br></pre></td></tr></table></figure>
<blockquote>
<p>请注意： <strong>修改权限很重要，否则将无法使用密钥连接</strong></p>
</blockquote>
<p>完成后，就可以向 <code>authorized_keys</code> 中粘贴公钥内容了</p>
<blockquote>
<p>如果在 Windows 中安装了 Git，可以在 Git Bash 环境下使用 Linux 命令，即可以像 Linux 一样创建密钥</p>
</blockquote>
<h3 id="3-连接">3 连接</h3>
<p>设置完成后，就可以免密连了</p>
<p>Linux 下，使用 <code>ssh</code> 命令</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ssh u&lt;user&gt;@&lt;服务器名或者 IP &gt;</span><br></pre></td></tr></table></figure>
<p>Putty 中需要设置：</p>
<p><img src="/images/2020/08/ssh-nopasswd-login/05.jpg" alt="Putty 设置"></p>
<blockquote>
<p>注意 Putty 使用的私钥文件后缀名是 <code>.ppk</code>，即通过 <code>Save private key</code> 按钮</p>
</blockquote>
<h2 id="总结">总结</h2>
<p>今天简单说明了下如何设置 SSH 免密登录，实际上设置过程比较简单。同时了解了下 SSH 协议，它是计算机安全领域的基础协议，同时验证了一句话：重要的东西往往是简单的。</p>
<h2 id="参考">参考</h2>
<ul>
<li><a href="http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html" target="_blank" rel="noopener">http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html</a></li>
<li><a href="https://jingyan.baidu.com/article/ea24bc39b42ec2da62b331df.html" target="_blank" rel="noopener">https://jingyan.baidu.com/article/ea24bc39b42ec2da62b331df.html</a></li>
<li><a href="https://www.cnblogs.com/ljmjjy0820/p/8045298.html" target="_blank" rel="noopener">https://www.cnblogs.com/ljmjjy0820/p/8045298.html</a></li>
</ul>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Linux/" rel="tag"># Linux</a>
              <a href="/tags/ssh/" rel="tag"># ssh</a>
              <a href="/tags/key/" rel="tag"># key</a>
          </div>

        

			<div id="wechat_subscriber" style="display: block; padding: 10px 0; margin: 20px auto; width: 100%; text-align: center">
    <img id="wechat_subscriber_qcode" src="/images/wechat-qcode.png" alt="太阳雪 wechat" style="width: 200px; max-width: 100%;"/>
    <div>关注我，获得更多精彩内容</div>
</div>

        
		
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020-08-05-base-logic-1/" rel="prev" title="为什么总是来不及反应">
      <i class="fa fa-chevron-left"></i> 为什么总是来不及反应
    </a></div>
      <div class="post-nav-item">
    <a href="/2020-08-07-survivorship-bias/" rel="next" title="为什么受伤的总是你">
      为什么受伤的总是你 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#什么是-SSH"><span class="nav-number">1.</span> <span class="nav-text">什么是 SSH</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#为什么要免密"><span class="nav-number">2.</span> <span class="nav-text">为什么要免密</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#设置-SSH"><span class="nav-number">3.</span> <span class="nav-text">设置 SSH</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-制作密钥对"><span class="nav-number">3.1.</span> <span class="nav-text">1 制作密钥对</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#ssh-keygen"><span class="nav-number">3.1.1.</span> <span class="nav-text">ssh-keygen</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#puttygen"><span class="nav-number">3.1.2.</span> <span class="nav-text">puttygen</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-向服务器推送公钥"><span class="nav-number">3.2.</span> <span class="nav-text">2 向服务器推送公钥</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#ssh-copy-id"><span class="nav-number">3.2.1.</span> <span class="nav-text">ssh-copy-id</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#手工推送"><span class="nav-number">3.2.2.</span> <span class="nav-text">手工推送</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-连接"><span class="nav-number">3.3.</span> <span class="nav-text">3 连接</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#总结"><span class="nav-number">4.</span> <span class="nav-text">总结</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#参考"><span class="nav-number">5.</span> <span class="nav-text">参考</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="太阳雪"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">太阳雪</p>
  <div class="site-description" itemprop="description">总结 技术 思考 想法</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">88</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">47</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">太阳雪</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  
  <script>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>















  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'teRj7yeJj0xpfGKLJ5uFdbIu-gzGzoHsz',
      appKey     : '3uie0p1nxouCCnkjiXTEBeLd',
      placeholder: "您的关注是我的动力",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
